import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/components/app_bar/app_bar_view.dart';
import 'package:pornhub_app/components/base_refresh/base_refresh_widget.dart';
import 'package:pornhub_app/components/image_view.dart';
import 'package:pornhub_app/components/no_more/no_data.dart';
import 'package:pornhub_app/components/star_cell/attention.dart';
import 'package:pornhub_app/components/text_view.dart';
import 'package:pornhub_app/generate/app_image_path.dart';
import 'package:pornhub_app/model/play/video_detail_model.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/extension.dart';

import '../controllers/activity_player_controller.dart';

class ActivityPlayerPage extends StatefulWidget {
  const ActivityPlayerPage({super.key});

  @override
  State<ActivityPlayerPage> createState() => _ActivityPlayerPageState();
}

class _ActivityPlayerPageState extends State<ActivityPlayerPage> {
  late ActivityPlayerController controller;
  late int activityId;
  String tag = '';
  @override
  void initState() {
    super.initState();
    activityId = Get.arguments["activityId"];
    tag = Get.arguments["activityId"].toString();
    controller = Get.put(ActivityPlayerController(activityId: activityId),
        tag: "${tag}");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _buildAppBar(),
      body: GetBuilder<ActivityPlayerController>(
          assignId: true,
          tag: tag,
          builder: (_) {
            return BaseRefreshWidget(
              controller,
              child: ListView.builder(
                  itemExtent: 84.w,
                  padding: EdgeInsets.only(left: 14.w, right: 14.w, top: 20.w),
                  itemCount: controller.userItems.length,
                  itemBuilder: (context, index) {
                    var user = controller.userItems[index];
                    return Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            ImageView(
                              src: user.logo ?? "",
                              width: 60.w,
                              height: 60.w,
                              borderRadius: BorderRadius.circular(60.w),
                            ),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                TextView(
                                  text: '${user.nickName}',
                                  style: TextStyle(
                                      fontSize: 14.w, color: COLOR.white),
                                ),
                                TextView(
                                  text: '注册时长：1年内  参加活动：${user.joinNum}次',
                                  style: TextStyle(
                                      fontSize: 12.w,
                                      color: const Color.fromRGBO(
                                          255, 255, 255, 0.54)),
                                ).marginTop(6.w),
                              ],
                            ).paddingLeft(12.w)
                          ],
                        ),
                        Container(
                          width: 64.w,
                          height: 27.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(13.5.w),
                              border: Border.all(color: COLOR.color_B940FF)),
                          child: TextView(
                            text: user.isAttention == true ? '已关注' : '关注',
                            style: TextStyle(
                                fontSize: 12.w, color: COLOR.color_B940FF),
                          ),
                        ).onOpaqueTap(() async {
                          var r = await controller.focus(user.userId!,
                              attention: user.isAttention);
                          if (r) {
                            user.isAttention = !user.isAttention!;
                            setState(() {});
                          }
                        })
                      ],
                    ).marginBottom(20.w);
                  }),
            );
          }),
    );
  }

  PreferredSizeWidget _buildAppBar() => AppBarView(
        titleText: '已报名',
      );
}
